#include <iostream>
using namespace std;

class Test
{
public:
    //思想：双指针
    //时间复杂度：O(N) 空间复杂度O(1)
    int removeDuplicates(int *nums, int numsSize)
    {
        int src = 1;
        int dst = 0;
        while (src < numsSize)
        {
            if (nums[src] == nums[src - 1])
            {
                src++;
            }
            else
            {
                nums[dst] = nums[src - 1];
                src++;
                dst++;
            }
        }
        // src最后越界了，跟src-1比较不了，必须把nums中numsSize - 1元素的值添加到dst上
        nums[dst] = nums[numsSize - 1];
        dst++;
        return dst;
    }
};

int main()
{
    int nums[10];
    for (int i = 0; i < 10; ++i)
    {
        cin >> nums[i];
    }

    Test t;
    int Size = t.removeDuplicates(nums, sizeof(nums) / sizeof(nums[0]));
    for (int i = 0; i < Size; ++i)
    {
        cout << nums[i] << ' ';
    }
    cout << '\n';
    system("pause");
    return 0;
}